//
//  RHAddDeviceCell.m
//  RuiHeAppApp
//
//  Created by Jun on 2023/7/27.
//

#import "RHAddDeviceCell.h"
@interface RHAddDeviceCell()
@property (nonatomic ,strong) UIImageView *arrowImg;

@property (nonatomic ,strong) UIView *line;
@end
@implementation RHAddDeviceCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self setupUI];
    }
    
    return self;
}


-(void)setTopBorder
{
    self.bgView.layer.cornerRadius = 8;
    self.bgView.qmui_borderColor = kBorderColor;
    self.bgView.qmui_borderWidth = 1;
    self.bgView.qmui_borderPosition = QMUIViewBorderPositionLeft|QMUIViewBorderPositionTop|QMUIViewBorderPositionRight;
    self.bgView.layer.qmui_maskedCorners = QMUILayerMinXMinYCorner|QMUILayerMaxXMinYCorner;
    self.bgView.layer.masksToBounds = YES;
}
-(void)setMiddleBorder
{
    self.bgView.layer.cornerRadius = 0;
    self.bgView.qmui_borderColor = kBorderColor;
    self.bgView.qmui_borderWidth = 1;
    self.bgView.qmui_borderPosition = QMUIViewBorderPositionLeft|QMUIViewBorderPositionRight;
    self.bgView.layer.masksToBounds = YES;
}
-(void)setBottomBorder
{
    self.bgView.layer.cornerRadius = 8;
    self.bgView.qmui_borderColor = kBorderColor;
    self.bgView.qmui_borderWidth = 1;
    self.bgView.qmui_borderPosition = QMUIViewBorderPositionLeft|QMUIViewBorderPositionBottom|QMUIViewBorderPositionRight;
    self.bgView.layer.qmui_maskedCorners = QMUILayerMinXMaxYCorner|QMUILayerMaxXMaxYCorner;
    self.bgView.layer.masksToBounds = YES;
}

-(void)hideArrowView:(BOOL)hidden
{
    self.arrowImg.hidden = hidden;
    [self.arrowImg mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.offset(hidden?0:15);
    }];
}

-(void)hideLine:(BOOL)hidden
{
    self.line.hidden = hidden;
}

- (void)setupUI{
    
    [self setBackgroundColor:UIColor.clearColor];
    [self.contentView setBackgroundColor:UIColor.clearColor];
    
    _bgView = [[UIView alloc] init];
    [_bgView setBackgroundColor:UIColor.whiteColor];
    [self.contentView addSubview:_bgView];
    
    _titleLab = [[QMUILabel alloc] init];
    [_titleLab setTextAlignment:NSTextAlignmentLeft];
    [_titleLab setFont:[UIFont systemFontOfSize:14]];
    [_titleLab setTextColor:kCOLOR_HEX(@"3F4443")];
    _titleLab.numberOfLines = 2;
    _titleLab.adjustsFontSizeToFitWidth = YES;
    _titleLab.minimumScaleFactor = 0.8;
    [_bgView addSubview:_titleLab];
    
    _textField = [[QMUITextField alloc] init];
    [_textField setTextAlignment:NSTextAlignmentLeft];
    [_textField setTextColor:[kCOLOR_HEX(@"3F4443") colorWithAlphaComponent:0.8]];
    [_textField setFont:[UIFont systemFontOfSize:14]];
    [_textField setPlaceholder:@"Please input"];
    [_bgView addSubview:_textField];
    
    UIImageView *arrowImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow_down"]];
    [_bgView addSubview:arrowImg];
    self.arrowImg = arrowImg;
    [arrowImg mas_makeConstraints:^(MASConstraintMaker *make) {
                make.width.height.offset(15);
                make.centerY.mas_offset(0);
                make.right.mas_offset(-15);
    }];
    
    UIView *lineV = [[UIView alloc] init];
    [lineV setBackgroundColor:CFCellLineColor];
    self.line = lineV;
    [_bgView addSubview:lineV];
    
    
    kWeakSelf;
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0,15, 0, 15));
        make.height.mas_equalTo(50);
    }];
    
    [_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.height.mas_equalTo(30);
        make.centerY.mas_offset(0);
        make.width.mas_equalTo(100);
    }];
    
    [_textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.titleLab.mas_right).offset(5);
        make.right.equalTo(arrowImg.mas_left).offset(-5);
        make.height.mas_equalTo(30);
        make.centerY.mas_offset(0);
    }];
    
    [lineV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.bottom.mas_offset(0);
        make.height.mas_equalTo(1);
    }];
    
    [_titleLab setText:@"title"];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
